package com.hz.basic.service.impl;

import com.hz.basic.entity.CbExpandResourceEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.common.utils.PageUtils;
import com.hz.common.utils.Query;

import com.hz.basic.dao.CbExpandBrowseLogDao;
import com.hz.basic.entity.CbExpandBrowseLogEntity;
import com.hz.basic.service.CbExpandBrowseLogService;


@Service("cbExpandBrowseLogService")
public class CbExpandBrowseLogServiceImpl extends ServiceImpl<CbExpandBrowseLogDao, CbExpandBrowseLogEntity> implements CbExpandBrowseLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CbExpandBrowseLogEntity> page = this.page(
                new Query<CbExpandBrowseLogEntity>().getPage(params),
                new QueryWrapper<CbExpandBrowseLogEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getlog(long userId, int addType, Long cid, String condition, int curpage,int numpage) {
        int total = this.baseMapper.getlogtotal(userId, addType, cid, condition);
        //不合理的curpage，越界
        if(curpage <= 0 || Math.ceil((double)total/numpage) < curpage)
            return new PageUtils(new ArrayList<CbExpandResourceEntity>(),total,numpage,curpage);
        List<CbExpandResourceEntity> expandResources = this.baseMapper.getlog(userId, addType, cid, condition, (curpage-1)*numpage,numpage);
        PageUtils page = new PageUtils(expandResources,total,numpage,curpage);
        return page;
    }

}